package com.google.gwt.livinglife.client.widgets;

import java.util.Date;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.livinglife.client.StoryData;
import com.google.gwt.livinglife.client.data.BasicPostData;
import com.google.gwt.livinglife.client.data.UserIdData;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DecoratorPanel;
import com.google.gwt.user.client.ui.DockPanel;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TabPanel;

public class StoryBox extends Composite implements ClickHandler {
	StoryData data;
	private DecoratorPanel decoratorPanel = new DecoratorPanel();
	private DockPanel mainPanel = new DockPanel();
  private HorizontalPanel votingPanel = new HorizontalPanel();
  private Label titleBox = new Label();
  private TabPanel tabPanel = new TabPanel();
  private AuthoredTextBox story_widget;
  private AuthoredTextBox challenge_widget;
  private Button likeButton = new Button("like");
  private Button inspiringButton = new Button("inspiring");
  private Button inappropriateButton = new Button("inappropriate");

	public StoryBox(StoryData story_data) {
		data = story_data;
		// Assemble the panel
		titleBox.setText(data.getTitle());
		mainPanel.add(titleBox, DockPanel.NORTH);
		votingPanel.add(likeButton);
		votingPanel.add(inspiringButton);
		votingPanel.add(inappropriateButton);
		votingPanel.setSpacing(3);
		mainPanel.add(votingPanel, DockPanel.SOUTH);
		BasicPostData post = new BasicPostData();
		UserIdData user = new UserIdData();
		user.setId("foobar");
		user.setNickname(data.getChallenge_author());
		post.setAuthor(user);
		post.setCreation_date(new Date());
		post.setAuthor(new UserIdData());
		post.setPost_text(data.getChallenge());
		challenge_widget = new AuthoredTextBox(post);
		challenge_widget.setWidth("350px");
		tabPanel.add(challenge_widget, "Challenge");
		
		// if (data.getResponse() != null && data.getResponse().length() > 0) {
		//	story_widget = new AuthoredTextBox(data.getResponse_author(), data
		//			.getResponse());
		//	story_widget.setWidth("350px");
		//	tabPanel.add(story_widget, "Response");
		// }
		tabPanel.selectTab(0);
		mainPanel.add(tabPanel, DockPanel.CENTER);
		mainPanel.setWidth("500px");
		decoratorPanel.setWidget(mainPanel);
		initWidget(decoratorPanel);

		// Give the overall composite a style name.
		// setStyleName("StoryBox");
	}
	
	public void onModuleLoad() {
	}

	public void onClick(ClickEvent event) {
		Object sender = event.getSource();
		if (sender == likeButton) {
			
		} else if (sender == inspiringButton) {
			
		} else if (sender == inappropriateButton) {
			
		}
	}
}
